/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;
import Model.*;
import javax.microedition.lcdui.*;

/**
 *
 * @author Pisarchik_S
 */
public class EditEmailSettings implements CommandListener {
    Dispatcher m_Dispatcher;
    EMailSettings m_Settings;

    Command m_CancelCommand = new Command("Скасаваць", Command.CANCEL, 0);
    Command m_OkCommand = new Command("Ужыць", Command.OK, 0);

    public EditEmailSettings(Dispatcher dispatcher, EMailSettings settings)
    {
        m_Dispatcher = dispatcher;
        m_Settings = settings;
    }

    TextField m_sSMTPServer;
    TextField m_sUserName;
    TextField m_sPassword;
    TextField m_sRecipient;
    TextField m_port;

    public void Init()
    {
        Form form = new Form("Рэдагаваць наладкі");

        m_sRecipient = new TextField("Адрас атрымальніка (vasia@mail.ru)", m_Settings.m_sRecipient, 50, TextField.PLAIN);
        form.append(m_sRecipient);
        
        m_sSMTPServer = new TextField("SMTP Сервэр (smtp.mail.ru): ", m_Settings.m_sSMTPServer, 30, TextField.PLAIN);
        form.append(m_sSMTPServer);
        
        m_port = new TextField("Порт (25)", Integer.toString(m_Settings.m_port), 4, TextField.NUMERIC);
        form.append(m_port);
        
        m_sUserName = new TextField("Імя карыстальніка (vasia@mail.ru): ", m_Settings.m_sUserName, 50, TextField.PLAIN);
        form.append(m_sUserName);
        
        m_sPassword = new TextField("Пароль (******): ", m_Settings.m_sPassword, 15, TextField.PASSWORD);
        form.append(m_sPassword);
        
        form.addCommand(m_OkCommand);
        form.addCommand(m_CancelCommand);
        form.setCommandListener(this);

        m_Dispatcher.GetDisplay().setCurrent(form);
    }

    public void commandAction(Command c, Displayable s)
    {
        if (c == m_CancelCommand)
        {
            m_Dispatcher.GetMainMenuEditor().Init();
        }
         if (c == m_OkCommand)
        {

             m_Settings.m_sPassword     = m_sPassword.getString();
             m_Settings.m_sRecipient    = m_sRecipient.getString();
             m_Settings.m_sUserName     = m_sUserName.getString();
             m_Settings.m_sSMTPServer   = m_sSMTPServer.getString();
             m_Settings.m_port          = Integer.parseInt(m_port.getString());
             m_Settings.Save();

             m_Dispatcher.GetMainMenuEditor().Init();
        }
    }


}
